<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="models.SiteConfigModel"%>
<%@page import="models.UserModel"%>
<%@page import="java.util.TreeMap"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="java.util.ArrayList"%>
<%
	TreeMap check = (TreeMap) request.getAttribute("check");
	String success = (String) request.getAttribute("success");
	UserModel user = (UserModel) request.getAttribute("user");
	SiteConfigModel siteConfig = (SiteConfigModel) request.getAttribute("config");
	String image = "";//UrlHelper.getServerUrl(request) + "/blobstore-serve?blob-key=" + siteConfig.getLogo();
	String form = (String) request.getAttribute("form");
%>


<jsp:include page="/demo/layouts/header.jsp">
    <jsp:param name="title" value="<%=siteConfig.getTitle()%>" />
    <jsp:param name="description" value="<%=siteConfig.getMetaDescription()%>" />
    <jsp:param name="keywords" value="<%=siteConfig.getMetaKeywords()%>" />
    <jsp:param name="ogsite_name" value="<%=siteConfig.getSiteName()%>" />
    <jsp:param name="ogtitle" value="<%=siteConfig.getTitle()%>" />
    <jsp:param name="ogurl" value="<%=UrlHelper.getServerUrl(request)%>" />
    <jsp:param name="ogimage" value="<%=image %>" />
    <jsp:param name="ogdescription" value="<%=siteConfig.getMetaDescription()%>" />
</jsp:include>

		<div class="dir">
			<a href="/home">Home</a> > <%=form.equalsIgnoreCase("edit") ? "Profile" : "Register" %>
		</div>
		<br />
		<div class="submit-form">
			<form action="" method="post">
			<% if (success != null) { %>
			<div class="success"><%=success %></div>
			<% } %>
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form"><%=form.equalsIgnoreCase("edit") ? "Thông tin cá nhân" : (form.equalsIgnoreCase("add") ? "Đăng ký" : "Đổi mật khẩu" ) %></div></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td width="30%" class="username">Địa chỉ Email</td>
						<td>
							<% if (check.get("username") != null) { %>
								<div class="error"><%=check.get("username")%></div>
							<% } %>
							<% if (form.equalsIgnoreCase("add")) { %>
							<input type="text" name="username" value="<%=user.getUsername()%>" />
							<% } else { %>
								<%=user.getUsername()%>
							<% } %>
						</td>
					</tr>
					<% if (!form.equalsIgnoreCase("changePassword")) { %>
						<% if (form.equalsIgnoreCase("add")) { %>
						<tr>
							<td width="30%" class="password">Mật khẩu</td>
							<td>
								<% if (check.get("password") != null) { %>
									<div class="error"><%=check.get("password")%></div>
								<% } %>
								<input type="password" name="password" value="<%=user.getPassword() != null ? user.getPassword() : ""%>" />
							</td>
						</tr>
						<tr>
							<td width="30%" class="repassword">Xác nhận mật khẩu</td>
							<td>
								<% if (check.get("repassword") != null) { %>
									<div class="error"><%=check.get("repassword")%></div>
								<% } %>
								<input type="password" name="repassword" value="<%=user.getRePassword() != null ? user.getRePassword() : ""%>" />
							</td>
						</tr>
						<% } %>
						<tr class="dotline">
							<td width="30%" class="name">Tên hiển thị</td>
							<td>
								<% if (check.get("name") != null) { %>
									<div class="error"><%=check.get("name")%></div>
								<% } %>
								<input type="text" name="name" value="<%=user.getName()%>" />
							</td>
						</tr>
						<tr>
							<td width="30%" class="gender">Giới tính</td>
							<td>
								<% if (check.get("gender") != null) { %>
									<div class="error"><%=check.get("gender")%></div>
								<% } %>
								Nam <input type="radio" name="gender" value="0" checked="checked"/>
								Nữ <input type="radio" name="gender" value="1" />
							</td>
						</tr>
						<tr>
							<td width="30%" class="birthday">Ngày Sinh</td>
							<td>
								<% if (check.get("birthday") != null) { %>
									<div class="error"><%=check.get("birthday")%></div>
								<% } %>
								<select name="day">
									<option value="">Ngày</option>
									<% for (int i = 1; i <= 31; i++) { %>
									<option value="<%=i < 10 ? "0"+i : i %>" <%=i == Integer.parseInt(user.getDay()) ? "selected=\"selected\"" : "" %>><%=i %></option>
									<% } %>
								</select>
								
								<select name="month">
									<option value="">Tháng</option>
									<% for (int i = 1; i <= 12; i++) { %>
									<option value="<%=i < 10 ? "0"+i : i %>" <%=i == Integer.parseInt(user.getMonth()) ? "selected=\"selected\"" : "" %>><%=i %></option>
									<% } %>
								</select>
								
								<select name="year">
									<option value="">Năm</option>
									<% for (int i = 2012; i > 1900; i--) { %>
									<option value="<%=i %>" <%=i == Integer.parseInt(user.getYear()) ? "selected=\"selected\"" : "" %>><%=i %></option>
									<% } %>
								</select>
							</td>
						</tr>
						<tr class="dotline">
							<td class="title">Captcha</td>
							<td>
								<% if (check.get("captcha") != null) { %>
									<div class="error"><%=check.get("captcha")%></div>
								<% } %>
								<script>
						        	var RecaptchaOptions = { theme : 'clean' };
						  		</script>
								<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6LeA0c4SAAAAAMsdjrB49GPol6XImTdJM2U2AHrF"></script>
							</td>
						</tr>
					<% } else { %>
						<tr>
							<td width="30%" class="oldpassword">Mật khẩu cũ</td>
							<td>
								<% if (check.get("oldpassword") != null) { %>
									<div class="error"><%=check.get("oldpassword")%></div>
								<% } %>
								<input type="password" name="oldpassword" value="<%=user.getOldPassword() %>" />
							</td>
						</tr>
						<tr>
							<td width="30%" class="password">Mật khẩu mới</td>
							<td>
								<% if (check.get("password") != null) { %>
									<div class="error"><%=check.get("password")%></div>
								<% } %>
								<input type="password" name="password" value="<%=user.getPassword() %>" />
							</td>
						</tr>
						<tr>
							<td width="30%" class="repassword">Xác nhận mật khẩu mới</td>
							<td>
								<% if (check.get("repassword") != null) { %>
									<div class="error"><%=check.get("repassword")%></div>
								<% } %>
								<input type="password" name="repassword" value="<%=user.getRePassword() %>" />
							</td>
						</tr>
					<% } %>
					<tr>
						<td></td>
						<td>
							<button type="submit"><%=form.equalsIgnoreCase("add") ? "Thêm" : "Cập nhật" %></button>
						</td>
					</tr>
				</tbody>
			</table>
			</form>
		</div>
<jsp:include page="/demo/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>